<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .content{
            width:500px;
            margin:40px auto;
        }
        .search{
            width: 400px;
            overflow: hidden;
            
        }
        .search input{
            float: left;
        }
        #val{
            height: 35px;
            width: 300px;
            padding-left: 10px;
        }
        #sub{
            height: 40px;
            width: 80px;
            margin-left: 3px;
            font-size: 20px;
        }
        .show{
            width: 302px;
            height: 300px;
            border: 1px solid #ccc;
            padding-left: 10px;
            display: none;
        }
        .show p{
            font-size: 12px;
        }
    </style>
	<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
</head>
<body>
    <div class="content">
        <div class="search">
            <input type="text" id="val" placeholder="请输入课程">
            <input type="submit" id="sub">
        </div>
        <div class="show" id="show">
        </div>
    </div>
    <script>
        let arr = ['web前端精英特训班 980元','HTML核心技术 199元','CSS核心技术 299元','Vue核心技术 599元','CSS+HTML核心技术 299元','web前端在线商城 99元','JavaScript核心技术 399元','JavaScript高级技术 899元'];

        // 逻辑：1.先完成 展示区域的显示或隐藏
        // 
		$('#val').keyup(function() {
			let str = '';
			arr.forEach((item) =>{
				let res = item.indexOf($('#val').val());
				if(res != -1){
					str += '<p>' + item + '</p>';
				}
			})
			if($('#val').val() || !str){
				$('#show').css({'display': 'block'});
				$('#show').html(str);
			}
		});
		$('#val').blur(function () { 
			$('#show').css({'display': 'none'});			
		} );
		
		$('#val').keydown( function(event) {
			if(event.keyCode === 13){
				location.href = 'https://www.baidu.com/s?wd=' + $('#val').val();
			}
		})
	
		$('#sub').click(function() {
			location.href = 'https://www.baidu.com/s?wd=' + $('#val').val();
		})

    </script>
</body>
</html>